package com.chhuang.component;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

/**
 * @ClassName I18nMessage
 * @Description 国际化信息转化组件
 * @Author Darren Huang
 * @Date 2022/11/20 20:13
 * @Version 1.0
 */
@Component
public class I18nMessage {

//    INSTANCE;

    @Autowired
    private MessageSource messageSource;

    public String get(Integer code){
        return get(String.valueOf(code));
    }

    public String get(String key) {
        try {
            return messageSource.getMessage(key, null, LocaleContextHolder.getLocale());
        } catch (Exception e) {
            e.printStackTrace();
            return key;
        }
    }
}
